package com.example.demo.OtherCoding;

import java.util.HashMap;
import java.util.HashSet;

class Code_characterReplacement {
    public static int characterReplacement(String s, int k) {
        int left = 0;
        int right = 0;
        HashSet<Integer> set = new HashSet<>();
        char[] str = s.toCharArray();
        int[] count = new int[26];
        int maxCnt = 0;
        int res = 0;
        while(right < s.length()) {
            count[str[right] - 'A'] ++;
            maxCnt = Math.max(maxCnt,count[str[right]-'A']);
            right ++;
            if((right-left-maxCnt) > k) {
                count[str[left] - 'A'] --;
                left ++;
            }
        }
        return right - left;
    }

    public static void main(String[] args) {
        characterReplacement("AABCABBB",1);
    }
}